package cn.edu.scau.cmi.wujiaxian.comprehensive.service;

import java.util.ArrayList;

import cn.edu.scau.cmi.wujiaxian.comprehensive.dao.ClazzDao;
import cn.edu.scau.cmi.wujiaxian.comprehensive.dao.CourseDao;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Clazz;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Course;

public class ClazzService {
	
	public static void main(String[] args) {
		ClazzService clazzService = new ClazzService();
//		clazzService.addClazz("2017级软件工程6班");
		clazzService.deleteClazz("2017级软件工程2班");
		
	}
	
	/**
	 * 增加一个班级
	 * @param major
	 * @param grade
	 * @param number
	 */
	public void addClazz(String graceAndMajorAndClazz) {
		Clazz clazz = new Clazz();
		clazz.setGraceAndMajorAndClazz(graceAndMajorAndClazz);
		
		ClazzDao clazzDao = new ClazzDao();
		clazzDao.add(clazz);
	}
	
	/**
	 * 删除一个班级
	 * @param major
	 * @param grade
	 * @param number
	 */
	public void deleteClazz(String graceAndMajorAndClazz) {
		ClazzDao clazzDao = new ClazzDao();
		ArrayList<Clazz> clazzs = clazzDao.select("graceAndMajorAndClazz", graceAndMajorAndClazz);
		if (clazzs != null) {
			clazzDao.delete("id", clazzs.get(0).getId());
		}
	}
	
	/**
	 * 返回该课程编号的所有班级
	 * @param courseNumber
	 * @return
	 */
	public ArrayList<Clazz> selectClazzs(String courseNumber) {
		CourseDao courseDao = new CourseDao();
		ArrayList<Course> courses = courseDao.select("courseNumber", courseNumber);
		ArrayList<Clazz> clazzs = new ArrayList<>();
		for (Course course : courses) {
			ClazzDao clazzDao = new ClazzDao();
			ArrayList<Clazz> clazz = clazzDao.select("id", course.getClazzId());
			clazzs.add(clazz.get(0));
		}
		return clazzs;
	}
	
}
